using System;

namespace StreetPacMan.Server
{
    public partial class PacManDataContext
    {
        public void AddGameEvent(EventType eventType, string description, int playerId, int gameId)
        {
            Events.InsertOnSubmit(new Event
            {
                TypeEnum = eventType,
                ReceivedAt = DateTime.Now,
                GameId = gameId,
                Description = description
            });
            Messages.InsertOnSubmit(new Message
            {
                GameId = gameId,
                At = DateTime.Now,
                IsGameMessage = true,
                SenderId = playerId,
                Text = description,
            });
        }

        public void AddGameEvent(EventType eventType, string description, Player sender, Game game)
        {
            Events.InsertOnSubmit(new Event
            {
                TypeEnum = eventType,
                ReceivedAt = DateTime.Now,
                Game= game,
                Description = description
            });
            Messages.InsertOnSubmit(new Message
            {
                Game = game,
                At = DateTime.Now,
                IsGameMessage = true,
                //SenderId = sender,
                Text = description,
            });
        }

        public void AddPlayerMessage(string messageText, Player player)
        {
            Events.InsertOnSubmit(new Event
            {
                TypeEnum = EventType.ExplicitMessageSent,
                ReceivedAt = DateTime.Now,
                GameId = player.GameId,

                Description = string.Format("{0} said '{1}'", player.Name, messageText)
            });
            Messages.InsertOnSubmit(new Message
            {
                GameId = player.GameId,
                At = DateTime.Now,
                IsGameMessage = true,
                SenderId = player.Id,
                Text = messageText,
            });
        }
    }

    public partial class Event
    {
        public EventType TypeEnum
        {
            get { return (EventType)Type; }
            set { Type = (int)value; }
        }
    }
    public partial class Apple
    {
        public AppleKind KindEnum
        {
            get { return (AppleKind)Kind; }
            set { Kind = (int)value; }
        }
    }

    public partial class Player
    {
        public PlayerRole RoleEnum
        {
            get { return (PlayerRole)Role; }
            set { Role = (int)value; }
        }
        public PlayerState StateEnum
        {
            get { return (PlayerState)State; }
            set { State = (int)value; }
        }
    }
    public partial class Game
    {
        public GameState StateEnum
        {
            get { return (GameState)State; }
            set { State = (int)value; }
        }


        public void AddGameEvent(EventType eventType, string description, int senderPlayerId)
        {
            Events.Add(new Event
            {
                TypeEnum = eventType,
                ReceivedAt = DateTime.Now,
                Description = description
            });
            Messages.Add(new Message
            {
                At = DateTime.Now,
                IsGameMessage = true,
                SenderId = senderPlayerId,
                Text = description,
            });
        }
    }
}